package com.cocotingo.snail.template.models;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.cocotingo.snail.template.TemplateSyntaxException;

public class ResourcesNode extends Node {
	
	private final List<ResourceNode> resources;
	
	public ResourcesNode() {
		resources = new ArrayList<ResourceNode>();
	}
	
	public final void addResourceNode(ResourceNode node) {
		this.addResourceNode(node, resources.size());
	}
	
	public void addResourceNode(ResourceNode node, int index) {
		if (node == null) throw new IllegalArgumentException("cannot add null as a child node");
		resources.add(index, node);
	}
	
	public boolean removeResourceNode(ResourceNode node) {
		return resources.remove(node);
	}
	
	public Iterable<ResourceNode> resourceNodes() {
		return new Iterable<ResourceNode>() {
			@Override
			public Iterator<ResourceNode> iterator() {
				return resources.iterator();
			}
		};
	}
	
	public int resourceNodeCount() {
		return resources.size();
	}

	@Override
	public void validateNode() throws TemplateSyntaxException {
	}

	@Override
	public Iterable<ResourceNode> children() {
		return resourceNodes();
	}

	@Override
	protected String getXMLNodeName() {
		return "Resources";
	}

	@Override
	protected String getXMLAttributes() {
		return null;
	}

}
